﻿using MD5Hash;
using MediatR;
using Microsoft.IdentityModel.Tokens;
using RBAC.ApiReads.Application.Command;
using RBAC.ApiReads.DTO;
using RBAC.Domain.RbacEntity;
using RBAC.Infrasturcture.Interfaces;
using RBAC.ResultCode;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;

namespace RBAC.ApiReads.Application.Commandhandler
{
    public class GetPermissionCommandhandler : IRequestHandler<GetPermissionCommand, ApiResult<List<Permission>>>
    {
        private readonly IBaseRepository<Permission> permissionrepository;

        public GetPermissionCommandhandler(IBaseRepository<Permission> permissionrepository)
        {
            this.permissionrepository = permissionrepository;
        }
        public async Task<ApiResult<List<Permission>>> Handle(GetPermissionCommand request, CancellationToken cancellationToken)
        {

            var info = permissionrepository.GetAll();
            if (!string.IsNullOrEmpty(request.PermissionName)) 
            {
                info = info.Where(x => x.PermissionName == request.PermissionName);
            }

            return new ApiResult<List<Permission>> {
              Code=ApiResultEnum.查询成功,
              Message=ApiResultEnum.查询成功.ToString(),
              Data=info.ToList()
            };
        }


    }
}
